<template>
	<view class="container">
		<view class="user bg-fff">
			<!-- <view :style="'height:' + Top + 'px'"></view> -->
			<view class="search_box">
				<view class="restBox">
					<view class="restBox_txt" @click="restBoxType = !restBoxType">{{ userDelivery.is_rest == 1 ? "接单中" :
				"休息中"
						}}
						<u-icon class="restBox_Img" name="arrow-down" color="#000" size="28"></u-icon>
					</view>
					<view v-if="restBoxType" class="restItem">
						<view v-for="(item, ind) in restList" class="restItem_txt" :key="ind" @click="restBoxFun(ind)"
							:style="ind == 0 ? 'border-bottom: 1px solid #cacaca;' : ''">{{
				item.head }}</view>
					</view>
				</view>
				<u-search style="flex: 1;" @click="jump('/pages/mine/delivery/search')" placeholder="请输入商品名称" :show-action="false"
					v-model="keyword" disabled></u-search>
			</view>

			<view class="user-con flex-align-center">
				<image class="user-image" v-if="userDelivery.user"
					:src="userDelivery.user.avatarUrl || $setting.avatarUrl()"></image>
				<view class="user-info">
					<view class="user-name flex-space-between">
						<view>姓名：{{ userDelivery.real_name || "" }}</view>
						<view v-if="userDelivery.store">所属前置仓：{{ userDelivery.store.store_name || "" }}</view>
					</view>
					<view class="user-phone">手机号：{{ userDelivery.mobile || "" }}</view>
				</view>
			</view>

			<view class="tabs" style="width: 100vw;">
				<u-tabs :list="tabsList" :active-color="$setting.colorTheme()" :is-scroll="false" :current="tabsCurrent"
					@change="tabsChange" count="badgeCount"></u-tabs>
			</view>
		</view>
		<view class="user-placeholder" :style="'marginTop:' + Top + 'px'"></view>

		<view class="delivery-list">
			<view class="delivery-item bg-fff" v-for="(item, index) in deliveryList" :key="index"
				@click="jump('/pages/mine/delivery/delivery_info?order_id=' + item.order_id +'&tabsCurrent='+ tabsCurrent +'&token_type=1')">
				<view class="delivery-item-status flex-center">
					<text v-if="tabsCurrent == 0">{{ item.state_text }}</text>
					<text v-if="tabsCurrent == 1">{{ item.state_text }}</text>
					<text v-if="tabsCurrent == 2">{{ item.deliver_time_text }}</text>
					<text v-if="tabsCurrent == 3">已完成</text>
				</view>

				<view class="delivery-item-operate flex-space-between" style="margin-top: 0;">
					<view class="delivery-item-remark">订单编号：{{ item.order_no }}</view>
				</view>

				<view class="product-item flex" v-for="(it, idx) in item.product" :key="idx">
					<image class="product-item-image" :src="it.image.file_path"></image>
					<view class="product-item-con">
						<view class="product-item-name u-line-1">{{ it.product_name }}</view>
						<view class="product-item-suk">{{ it.product_attr }}</view>
						<view class="flex-space-between">
							<view class="product-item-num">x{{ it.total_num }}</view>
							<view class="product-item-price">￥{{ it.product_price }}</view>
						</view>
					</view>
				</view>
				<view class="product-item flex product-item-gift" v-if="item.gift_product_order">
					<image style="width: 100rpx;height: 100rpx;" :src="item.gift_product_order.file.file_path"></image>
					<view class="product-item-con">
						<view class="product-item-name u-line-1">{{item.gift_product_order.gift_product.product_name}}</view>
						<view class="product-item-suk"></view>
						<view class="flex-space-between">
							<view class="product-item-num">x1</view>
							<view class="product-item-price">赠品</view>
						</view>
					</view>
				</view>

				<view class="flex-space-between product-total">
					<view>优惠：<text>￥{{ item.coupon_money_sys }}</text></view>
					<view>总价：<text>￥{{ item.total_price }}</text></view>
					<view>实付：<text>￥{{ item.pay_price }}</text></view>
				</view>

				<view class="delivery-item-address flex">
					<view class="delivery-item-address-song flex-center">送</view>
					<view class="delivery-item-address-test">
						{{ item.address.region.province }}{{ item.address.region.city }}{{ item.address.region.region
						}}{{ item.address.detail }}{{item.address.house_number?item.address.house_number:''}}
					</view>
				</view>

				<view class="delivery-item-operate flex-space-between">
					<view class="delivery-item-remark">备注：{{ item.buyer_remark }}</view>
					<!-- <b-u-button-theme width="182rpx" height="56rpx" size="26rpx" @click="handleReceiving(item)" v-if="(tabsCurrent == 0 || tabsCurrent == 1) && (item.order_source != 30 || (item.order_source == 30 && item.assemble_status == 20))">立即接单</b-u-button-theme>
					
					<b-u-button-grey width="182rpx" height="56rpx" size="26rpx" v-if="(tabsCurrent == 0 || tabsCurrent == 1) && item.order_source == 30 && item.assemble_status != 20">立即接单</b-u-button-grey>
					
					<b-u-button-theme width="182rpx" height="56rpx" size="26rpx" @click="jump('/pages/mine/delivery/finish?order_id='+item.order_id)" v-if="tabsCurrent == 2">已送达</b-u-button-theme> -->
				</view>

				<view class="delivery-item-operate flex-space-between">
					<view class="delivery-item-remark"></view>
					<view class="flex-align-center">
						<b-u-button-theme width="182rpx" height="56rpx" size="26rpx" @click="handleReceiving(item)"
							v-if="(tabsCurrent == 0 || tabsCurrent == 1) && (item.order_source != 30 || (item.order_source == 30 && item.assemble_status == 20))">立即接单</b-u-button-theme>
						<b-u-button-grey width="182rpx" height="56rpx" size="26rpx"
							v-if="(tabsCurrent == 0 || tabsCurrent == 1) && item.order_source == 30 && item.assemble_status != 20">立即接单</b-u-button-grey>

						<template v-if="tabsCurrent == 2">
							<!-- 未转单 -->
							<view class="flex" v-if="item.is_transfer == 0">
								<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
									@click="userSelfFun(item.order_id)"
									v-if="item.is_claim == 0" style="margin-right: 30rpx;">用户自提</b-u-button-theme>
								<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
									@click="servicePop(item.order_id, item.is_claim)" style="margin-right: 30rpx;"
									v-if="item.is_transfer == 0">转单</b-u-button-theme>

								<!-- <template v-if="item.is_transfer == 0"> -->
								<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
									@click="jump('/pages/mine/delivery/pick_delivery?order_id=' + item.order_id)"
									v-if="item.is_claim == 0">待取货</b-u-button-theme>
								<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
									@click="jump('/pages/mine/delivery/finish?order_id=' + item.order_id)"
									v-if="item.is_claim != 0" style="margin-left: 20rpx;">待送达</b-u-button-theme>
								<!-- </template> -->
							</view>
							<!-- 已转单 -->
							<view v-if="item.is_transfer == 1">
								<template v-if="item.store_clerk_id == userDelivery.clerk_id">
									<view class="flex" v-if="item.is_clerk_shipping != 1">
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											style="margin-right: 20rpx;"
											@click="cancelTransfer(item.order_id, 0)">拒绝转单</b-u-button-theme>
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											style="margin-right: 20rpx;"
											@click="completeTransfer(item.order_id, 0)">立即接单</b-u-button-theme>
									</view>
								</template>

								<template v-else-if="item.transfer_ckid == userDelivery.clerk_id">
									<!-- 已接单 -->
									<view class="flex">
										<view v-if="item.is_clerk_shipping != 1">
											<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
												style="margin-right: 20rpx;"
												@click="cancelTransfer(item.order_id, 0)">取消转单</b-u-button-theme>
										</view>
											<view class="transferred_order">已转单</view>
											<view class="transferred_time">{{ item.transfer_ctime | date("dd日 hh:MM:ss") }}
									</view>
									</view>
								</template>
								<template v-else>
									<!-- 已接单 -->
									<view class="flex">
											<view class="transferred_order">已转单</view>
											<view class="transferred_time">{{ item.transfer_ctime | date("dd日 hh:MM:ss") }}
									</view>
									</view>
								</template>
							</view>
							<!-- 二次转单 -->
							<template v-if="item.is_clerk_shipping == 1">
								<template v-if="item.store_clerk_id == userDelivery.clerk_id">
									<view class="flex" v-if="item.is_transfer != 0">
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											@click="servicePop(item.order_id, item.is_claim)"
											style="margin-right: 30rpx;">转单</b-u-button-theme>
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											@click="jump('/pages/mine/delivery/pick_delivery?order_id=' + item.order_id)"
											v-if="item.is_clerk_claim == 0">待取货</b-u-button-theme>
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											@click="jump('/pages/mine/delivery/finish?order_id=' + item.order_id)"
											v-if="item.is_clerk_claim != 0"
											style="margin-left: 20rpx;">待送达</b-u-button-theme>
									</view>

								</template>
								<!-- <template v-else>
									<view class="flex" v-if="item.is_transfer != 0">
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											@click="servicePop(item.order_id, item.is_claim)"
											style="margin-right: 30rpx;">转单</b-u-button-theme>
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											@click="jump('/pages/mine/delivery/pick_delivery?order_id=' + item.order_id)"
											v-if="item.is_claim == 0">待取货</b-u-button-theme>
										<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
											@click="jump('/pages/mine/delivery/finish?order_id=' + item.order_id)"
											v-if="item.is_claim != 0" style="margin-left: 20rpx;">待送达1</b-u-button-theme>
									</view>
								</template> -->
							</template>


							<!-- <view v-if="item.is_transfer == 1 && item.is_shipping == 0" class="flex">
								<b-u-button-theme width="182rpx" height="56rpx" size="26rpx"
									style="margin-right: 30rpx;"
									@click="cancelTransfer(item.order_id, 1)">取消转单1</b-u-button-theme>
								<view class="transferred_order">已转单</view>
								<view class="transferred_time">{{ item.single_time | date("dd日 hh:MM:ss") }}</view>
							</view> -->

						</template>
					</view>
				</view>

				<view class="delivery-item-time" v-if="tabsCurrent == 3 && item.receipt_time">送达时间：{{ item.receipt_time }}</view>
				<view class="delivery-item-time" v-if="tabsCurrent == 3 && item.delivery_type.value==20">用户自提</view>
			</view>
		</view>

		<view>
			<b-u-loadmore :status="loadmoreStatus"></b-u-loadmore>
		</view>
		<!-- <view v-else style="padding-top: 100rpx;">
			<u-empty text="暂无数据" mode="data"></u-empty>
		</view>
		 -->
		<view class="strategy_pop" v-if="guide === true">
			<view class="image bg-fff">
				<view class="image-title">拍照验证</view>
				<view class="image-tips">为了避免货物纠纷，请在转单时进行检查并拍照存证</view>
				<u-upload width="150rpx" height="150rpx" :header="{ 'Cookie': 'XDEBUG_TRIGGER=;' }" :form-data="{
				token: token,
				app_id: app_id,
			}" name="iFile" :action="$setting.baseUrl() + '/file.upload/image'"
					@on-choose-complete="handleUploadChooseComplete()" @on-uploaded="handleUploaded()"
					@on-success="handleUploadSuccess" @on-remove="handleUploadRemove"></u-upload>

				<view class="pop_box">
					<view class="button_pop" @click="postClaimProduct" style="background-color: #BB0024;color: #fff;">
						确认提交
					</view>
					<view class="button_pop" @click="guide = false">取消</view>
				</view>
			</view>
		</view>

		<view class="strategy_pop" v-if="userSelf === true">
			<view class="image bg-fff">
				<view class="image-title">拍照验证</view>
				<view class="image-tips">为了避免货物纠纷，请在用户自提时进行检查并拍照存证</view>
				<u-upload width="150rpx" height="150rpx" :header="{ 'Cookie': 'XDEBUG_TRIGGER=;' }" :form-data="{
				token: token,
				app_id: app_id,
			}" name="iFile" :action="$setting.baseUrl() + '/file.upload/image'"
					@on-choose-complete="handleUploadChooseComplete()" @on-uploaded="handleUploaded()"
					@on-success="handleUploadSuccess" @on-remove="handleUploadRemove"></u-upload>

				<view class="pop_box">
					<view class="button_pop" @click="posuserPickupFun" style="background-color: #BB0024;color: #fff;">
						确认提交
					</view>
					<view class="button_pop" @click="userSelf = false">取消</view>
				</view>
			</view>
		</view>

		<u-popup v-model="serviceShow" mode="bottom" border-radius="24" closeable close-icon="close-circle"
			z-index="9999" close-icon-size="40">
			<view class="popup-service">
				<view class="popup-service-title">选择跑腿人员</view>
				<u-tabs :list="poptabsList" :active-color="$setting.colorTheme()" :is-scroll="false"
					:current="poptabsCurrent" @change="poptabsChange" :show-bar="false"></u-tabs>
				<view class="popup-search-title">
					<u-search :placeholder="placeholder" v-model="popkeyword" @search="onSearch"
						@custom="onSearch"></u-search>
				</view>
				<view class="popup-service-list">
					<scroll-view scroll-y="true" class="scroll-Y" style="height: 56vh">
						<view class="popup-service-item" v-for="(item, index) in service" :key="index">
							<template v-if="poptabsCurrent == 2">
								<view>
									<view class="flex">
										<view class="popup-service-name">
											<text style="color: #bb0024;margin-right: 20rpx;font-size: 36rpx;">{{ item.username }}</text>
											<text class="flex-cc-t" style="font-size: 26rpx;">{{item.mobile }}</text></view>
									</view>
									<view class="popup-service-name"><text class="flex-cc-b" style="font-size: 24rpx;margin-top: 6rpx;">所属小区：{{item.name }}</text></view>
								</view>
				
								<view v-if="item.is_rest == 1" class="popup-service-describe"
									@click="guidefun(item.id)">转单</view>
								<view v-else class="popup-service-describe popup-service-rest">休息中</view>
							</template>
							<template v-else>
								<view class="flex">
									<view class="popup-service-name flex-cc">
										<text class="flex-cc-t" style="font-size: 26rpx;"><text style="color: #bb0024;margin-right: 20rpx;font-size: 36rpx;">{{ item.real_name }}</text>{{ item.mobile }}</text>
										<text class="flex-cc-b" style="font-size: 24rpx;">所属前置仓：{{ item.store_name }}</text>
									</view>
									<!-- <view class="popup-service-name flex-cc" v-else>
										<text class="flex-cc-t">{{ item.real_name }}</text>
										<text class="flex-cc-b">{{ item.mobile }}</text>
									</view> -->
								</view>
								<view v-if="item.is_rest == 1" class="popup-service-describe"
									@click="guidefun(item.clerk_id)">转单</view>
								<view v-else class="popup-service-describe popup-service-rest">休息中</view>
							</template>
						</view>
					</scroll-view>
				</view>
			</view>
		</u-popup>
		<update-panel />
	</view>
</template>

<script>
export default {
	data() {
		return {
			restBoxType: false,
			resthead: "休息",
			restList: [{
				head: "接单",
			}, {
				head: "休息",
			}],
			token: uni.getStorageSync('token'),
			app_id: uni.$setting.appId,
			guide: false,
			keyword: "",
			Top: uni.getSystemInfoSync().statusBarHeight,
			userDelivery: {},
			tabsList: [
				{
					name: "接单",
					id: "delivery",
					badgeCount: 0
				},
				{
					name: "拼团接单",
					id: "assemble",
					badgeCount: 0
				},
				{
					name: "配送中",
					id: "received",
					badgeCount: 0
				},
				{
					name: "已完成",
					id: "comment",

				},
			],
			tabsCurrent: 0,
			deliveryList: [],
			pageForm: {
				order_source: 0,
				dataType: 'delivery',
				page: 1,
				pay_source: 'wx',
				list_rows: 10,
			},
			loadmoreStatus: 'nomore',

			sendTime: 0,
			serviceShow: false,
			service: [],
			serviceId: '',//订单id
			timeoutObj: null,//ws
			innerAudioContext: null,
			userInfo: {},
			poptabsList: [
				{
					name: "店内转",
					id: "1",
				},
				{
					name: "跨店转",
					id: "2",
				},
				{
					name: "社区骑手",
					id: "3",
				},
			],
			picksupList: [
				{
					name: "店内转",
					id: "1",
				},
				{
					name: "跨店转",
					id: "2",
				},
			],
			serviceList: [
				{
					name: "店内转",
					id: "1",
				},
				{
					name: "跨店转",
					id: "2",
				},
				{
					name: "社区骑手",
					id: "3",
				},
			],
			poptabsCurrent: 0,
			popkeyword: "",
			form: {
				image: [],
			},
			shopper_id: null,
			pickup: 0,//待取货  已取货
			userSelf:false,//用户自提
			userSelfId:'',
		}
	},
	onLoad() {
		//#ifdef APP-PLUS
		this.$checkUpdate().then(shouldUpdate => {
			if (shouldUpdate == true) {
				this.$showUpdateModal();
			}
		});
		//#endif
		// setTimeout(() => {
		// 	this.openConnection()
		// }, 500)
	},
	onShow() {
		this.restBoxType = false
		// this.innerAudioContext = uni.createInnerAudioContext();
		const token = uni.getStorageSync('token');
		if (token) {
			this.getHttp();
		}
	},
	onReachBottom() {
		if (this.loadmoreStatus == 'nomore') {
			return;
		}
		this.pageForm.page++;
		this.getDeliveryLists();
	},
	onPullDownRefresh() {
		this.search();
	},
	computed: {
		placeholder() {
			if (this.poptabsCurrent == 0) {
				return "姓名|手机号搜索"
			} else if(this.poptabsCurrent == 1){
				return "姓名|手机号|门店搜索"
			}else {
				return "小区名称搜索"
			}
		}
	},
	onUnload() {
		clearInterval(this.timeoutObj);
		this.innerAudioContext.stop();
		this.innerAudioContext.destroy();
		this.innerAudioContext.volume = 0;
	},
	methods: {
		restBoxFun(ind) {
			if (ind + 1 == this.userDelivery.is_rest) {
				return
			}
			let params = {
				username: '',
				avatar: '',
				is_rest: ind + 1// '1=营业，2=休息',
			}
			uni.$u.api.updateShopper(params).then(res => {
				uni.showToast({
					title: "修改成功",
				})
				this.restBoxType = false
				this.getUserDelivery()
			})
		},
		// 打开ws连接
		openConnection() {
			//心跳
			let self = this;
			this.reset();
			uni.closeSocket(); // 确保已经关闭 后 再 重新打开   
			uni.connectSocket({
				url: 'ws://120.79.251.198:2346', //ws接口地址
				method: 'post',
				success(res) {
					console.log('打开ws连接成功 connectSocket=', res);
				},
				fail(err) {
					console.log('打开ws连接失败 connectSocket=', err);
				}
			});

			let params = '';
			uni.onSocketOpen((res) => {
				// console.log('连接成功', res);
				uni.sendSocketMessage({
					// data: JSON.stringify(p arams),
					data: params,
					success(res) {
						// console.log('发送成功');
					},
					fail(err) {
						// console.log('发送失败');
					}
				});
			});
			self.onSocketMessage(); // 打开成功监听 服务器 返回的消息
		},
		//	打开成功监听服务器返回的消息
		onSocketMessage() { // 消息c
			let self = this;
			uni.onSocketMessage((res) => {
				let giveMsg = res.data;
				console.log(giveMsg, "================服务器消息");
				self.getSocketMsg(giveMsg); // 监听到有新服务器消息
			});
		},
		// 监听到有新服务器消息
		getSocketMsg(reData) {
			let self = this;
			let info = {};
			try {
				info = JSON.parse(reData);
				if (info.type == 'init') {
					self.userBind(info.client_id)
				} else if (info.type == "success") {
					let pages = {
						order_source: 0,
						dataType: 'shipping',
						page: 1,
						pay_source: 'wx',
						list_rows: 10,
					}
					if (self.deliveryList.length > 0 && self.pageForm.dataType == 'delivery') {
						self.deliveryList = []
					}
					if (self.deliveryList.length > 0 && self.pageForm.dataType == 'received') {
						self.deliveryList = []
					}
					setTimeout(() => {
						self.getDeliveryLists(pages)
					}, 2000)
					uni.createPushMessage({
						title: "酒秒达骑士",
						content: "您有新的酒秒达订单，请及时处理",
						sound: "system",
						success: (res) => {
							console.log("推送成功")
						},
						fail: (res) => {
							console.log("推送失败")
						}
					})
					self.innerAudioContext = uni.createInnerAudioContext();
					self.innerAudioContext.volume = 1;
					self.innerAudioContext.src = '/static/mp4.mp3';
					self.innerAudioContext.autoplay = true;
					self.innerAudioContext.play();
					self.innerAudioContext.loop = true;
				}
			} catch (e) {

			}
		},
		// 检测心跳reset
		reset() {
			clearInterval(this.timeoutObj);
			this.start(); // 启动心跳
		},
		// 启动心跳 start
		start() {
			let self = this;
			//0=ping 心跳
			let params = '';
			clearInterval(this.timeoutObj);
			this.timeoutObj = setInterval(function () {
				uni.sendSocketMessage({
					data: params,
					success: (res) => {
						console.log('连接中....');
					},
					fail: (err) => {
						console.log('连接失败重新连接....');
						self.openConnection();
					}
				});
			}, 30000);
		},

		userBind(client_id) {
			let params = {
				client_id: client_id,
				type: 2
			}
			uni.$u.api.userBind(params).then(res => {
				console.log("链接成功");
			})
		},



		timeStamp(value) {
			let date = new Date(value * 1000);
			let y = date.getFullYear();
			let MM = date.getMonth() + 1;
			MM = MM < 10 ? ('0' + MM) : MM;
			let d = date.getDate();
			d = d < 10 ? ('0' + d) : d;
			let h = date.getHours();
			h = h < 10 ? ('0' + h) : h;
			let m = date.getMinutes();
			m = m < 10 ? ('0' + m) : m;
			let s = date.getSeconds();
			s = s < 10 ? ('0' + s) : s;
			return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
		},
		servicePop(id, is_claim) {
			if (is_claim == 0) {
				this.poptabsList = this.picksupList
			} else {
				this.poptabsList = this.serviceList
			}
			this.pickup = is_claim
			this.serviceId = id
			setTimeout(() => {
				this.serviceShow = true
			}, 200)
		},
		handleUploadSuccess(e) {
			this.form.image.push(e.data.file_path);
		},
		handleUploadRemove(index) {
			this.form.image.splice(index, 1);
		},
		guidefun(id) {
			this.form.image = []
			this.shopper_id = id
			if (this.pickup == 0) {
				let params = {
					order_id: this.serviceId,
					shopper_id: this.shopper_id,
					stype: this.poptabsCurrent,
					image: this.form.image
				}
				uni.$u.api.transferOrder(params).then(res => {
					uni.showToast({
						title: "转单成功",
					})
					this.serviceShow = false
					this.guide = false
					this.pageForm.page = 1;
					this.pageForm.list_rows = this.deliveryList.length;
					this.getDeliveryLists();
				})
			} else {
				this.guide = true
			}
		},
		postClaimProduct() {
			if (!this.form.image || this.form.image.length == 0) {
				uni.showToast({
					title: "请拍照确认",
					icon: 'none'
				})
				return;
			}
			// let formImg = JSON.parse(JSON.stringify(this.form));
			let params = {
				order_id: this.serviceId,
				shopper_id: this.shopper_id,
				stype: this.poptabsCurrent,
				image: this.form.image
			}
			uni.$u.api.transferOrder(params).then(res => {
				uni.showToast({
					title: "转单成功",
				})
				this.serviceShow = false
				this.guide = false
				this.pageForm.page = 1;
				this.pageForm.list_rows = this.deliveryList.length;
				this.getDeliveryLists();
			})
		},
		userSelfFun(id){
			this.form.image = []
			this.userSelfId = id
			this.userSelf = true
		},
		posuserPickupFun(){
			if (!this.form.image || this.form.image.length == 0) {
				uni.showToast({
					title: "请拍照确认",
					icon: 'none'
				})
				return;
			}
			let params = {
				order_id: this.userSelfId,
				delivery_image: this.form.image
			}
			uni.$u.api.posuserPickup(params).then(res => {
				uni.showToast({
					title: "自提成功",
				})
				this.userSelf = false
				this.pageForm.page = 1;
				this.pageForm.list_rows = this.deliveryList.length;
				this.getDeliveryLists();
			})
		},
		transferOrder(id) {

		},
		jump(url) {
			uni.navigateTo({
				url: url
			})
		},
		handleReceiving(item) {
			if (item.order_source == 30) {
				if (item.assemble_status == 10 || item.assemble_status == 30) {
					uni.showToast({
						title: "拼团未完成，暂不可接单",
						icon: 'none'
					})
					return;
				}
			}

			uni.$u.api.postReceiving({ order_id: item.order_id }).then(res => {
				uni.showToast({
					title: "接单成功",
				})

				uni.getLocation({
					type: 'gcj02',
					success: (res) => {
						uni.$u.api.postAsyncSaveCoord({
							order_id: item.order_id,
							async_lng: res.longitude,
							async_lat: res.latitude,
						})
						// console.log('当前位置的经度：' + res.longitude);
						// console.log('当前位置的纬度：' + res.latitude);
					},
				});

				this.search();
			})
		},
		cancelTransfer(orderid, type) {
			let self = this;
			uni.showModal({
				title: '提示',
				content: '确定要取消转单吗？',
				success: function (res) {
					if (res.confirm) {
						uni.$u.api.cltransferOrder({
							order_id: orderid,
							stype: type
						}).then(res => {
							uni.showToast({
								title: "取消成功",
							})
							self.pageForm.page = 1;
							self.pageForm.list_rows = self.deliveryList.length;
							self.getDeliveryLists();
						})
					} else if (res.cancel) {
						// that.showerrormsg();
						console.log('用户点击取消');
					}
				}
			});
		},
		completeTransfer(orderid, type) {
			uni.$u.api.postShopperReceiving({ order_id: orderid }).then(res => {
				uni.showToast({
					title: "接单成功",
				})

				uni.getLocation({
					type: 'gcj02',
					success: (res) => {
						uni.$u.api.postAsyncSaveCoord({
							order_id: item.order_id,
							async_lng: res.longitude,
							async_lat: res.latitude,
						})
						// console.log('当前位置的经度：' + res.longitude);
						// console.log('当前位置的纬度：' + res.latitude);
					},
				});

				this.search();
			})
		},
		poptabsChange(e) {
			this.popkeyword = ""
			this.poptabsCurrent = e;
			this.service = [];
			this.getVillageList();
		},
		onSearch(e) {
			console.log(e,"123123123")
			this.popkeyword = e
			this.service = [];
			this.getVillageList();
		},
		tabsChange(e) {
			this.tabsCurrent = e;

			if (this.tabsList[e].id == "assemble") {
				this.$set(this.pageForm, 'order_source', 30);
				this.$set(this.pageForm, 'dataType', "delivery");
			} else {
				this.$set(this.pageForm, 'order_source', 0);
				this.$set(this.pageForm, 'dataType', this.tabsList[e].id);
			}

			this.search();
		},
		search() {
			this.pageForm.page = 1;
			this.deliveryList = [];
			this.getDeliveryLists();
		},
		getUserInfo() {
			uni.$u.api.userInfo().then(res => {
				this.userInfo = res;
			})
		},
		getDeliveryLists() {
			this.getOrderNum()
			this.loadmoreStatus = 'loading';
			uni.$u.api.getDeliveryLists(this.pageForm).then(res => {
				if (this.pageForm.page < 2) {
					this.deliveryList = res.list.data
				} else {
					this.deliveryList = this.deliveryList.concat(res.list.data);
				}
				this.loadmoreStatus = 'loadmore';
				if (this.deliveryList.length > 0 && this.pageForm.dataType == 'delivery' && this.pageForm.order_source == 0) {
					this.innerAudioContext = uni.createInnerAudioContext();
					this.innerAudioContext.volume = 1;
					this.innerAudioContext.src = '/static/mp4.mp3';
					this.innerAudioContext.autoplay = true;
					this.innerAudioContext.play();
					this.innerAudioContext.loop = true;
				} else if (this.deliveryList.length == 0 && this.pageForm.dataType == 'delivery' && this.pageForm.order_source == 0) {
					this.innerAudioContext.stop();
					this.innerAudioContext.destroy();
					this.innerAudioContext.volume = 0;
					this.innerAudioContext.loop = false;
				}
				if (this.deliveryList.length == res.list.total) {
					this.loadmoreStatus = 'nomore';
				}
				uni.stopPullDownRefresh();
			})
		},
		getUserDelivery() {
			uni.$u.api.getUserDelivery().then(res => {
				this.userDelivery = res;
			})
		},
		getConfigData() {
			uni.$u.api.getConfigData({ type: "sendTime" }).then(res => {
				this.sendTime = res.list[0].value;
			})
		},
		getConfigData() {
			uni.$u.api.getConfigData({ type: "sendTime" }).then(res => {
				this.sendTime = res.list[0].value;
			})
		},
		getOrderNum() {
			uni.$u.api.getOrderNum().then(res => {
				let countlist = res.countlist
				this.tabsList[0].badgeCount = countlist[0] || 0
				this.tabsList[1].badgeCount = countlist[1] || 0
				this.tabsList[2].badgeCount = countlist[2] || 0
			})
		},
		getHttp() {
			this.search();
			this.getUserDelivery()
			this.getConfigData();
			this.getVillageList();
		},
		getVillageList() {
			let poptype = this.poptabsCurrent
			let popsearch = this.popkeyword
			uni.$u.api.getVillageList({
				poptype: poptype,
				popsearch: popsearch
			}).then(res => {
				this.service = res.list
			})
		},
	},
}
</script>

<style lang="scss" scoped>
.container {

	.user {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 999;

		.search_box {
			margin: 20rpx 30rpx 10rpx 30rpx;
			display: flex;
			align-items: center;
		}

		.restBox {
			margin: 0 20rpx 0 10rpx;
			position: relative;

			.restItem {
				position: absolute;
				top: 50rpx;
				left: 0rpx;
				height: 160rpx;
				width: 200rpx;
				z-index: 99;
				border-radius: 0 30rpx 30rpx 30rpx;
				background: rgba(80, 80, 80, 0.9);
				// box-shadow: 0px 2px 2px 2px #acabab;

				.restItem_txt {
					color: #fff;
					text-align: center;
					line-height: 82rpx;
					font-weight: bold;
				}

			}

			.restBox_txt {
				display: flex;
				align-items: center;
				font-weight: bold;

				.restBox_Img {
					margin-left: 10rpx;
					width: 30rpx;
					height: 30rpx;
				}
			}
		}

		.user-con {
			padding: 26rpx 30rpx;

			.user-image {
				width: 84rpx;
				height: 84rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}

			.user-info {
				flex: 1;
				font-size: 24rpx;
				color: #666666;

				.user-phone {
					margin-top: 10rpx;
				}
			}
		}
	}

	.user-placeholder {
		height: 310rpx;
	}

	.delivery-list {
		padding: 30rpx;

		.delivery-item {
			padding: 34rpx;
			border-radius: 16rpx;
			position: relative;
			margin-bottom: 20rpx;

			.delivery-item-status {
				min-width: 174rpx;
				height: 56rpx;
				border-radius: 0rpx 16rpx 0rpx 16rpx;
				background: rgba(232, 13, 13, 0.1);
				padding: 0 5rpx;
				font-size: 24rpx;
				color: #E80D0D;
				position: absolute;
				top: 0;
				right: 0;
				z-index: 9;
			}
			.product-item-gift {
					margin: 10rpx 0;
					padding: 20rpx;
					background: rgba(225, 225, 225, 0.7);
					border-radius: 20rpx;
				}
			.product-item {
				margin-top: 20rpx;

				.product-item-image {
					width: 128rpx;
					height: 128rpx;
				}

				.product-item-con {
					margin-left: 16rpx;
					flex: 1;

					.product-item-name {
						width: 460rpx;
						font-size: 28rpx;
						color: #111111;
					}

					.product-item-suk {
						font-size: 24rpx;
						color: #999999;
						margin-bottom: 10rpx;
					}

					.product-item-num {
						font-size: 24rpx;
						color: #999999;
					}

					.product-item-price {
						font-size: 28rpx;
						color: $uni-color-theme;
					}
				}
			}

			.product-total {
				margin-top: 20rpx;
				font-size: 24rpx;

				text {
					color: $uni-color-theme;
				}
			}

			.delivery-item-address {
				margin-top: 32rpx;
				border-top: 1px solid rgba(225, 225, 225, 0.7);
				padding-top: 32rpx;

				.delivery-item-address-song {
					width: 56rpx;
					height: 56rpx;
					border-radius: 160rpx;
					background: #F6F6F6;
					font-size: 28rpx;
					color: #BB0024;
				}

				.delivery-item-address-test {
					font-size: 28rpx;
					color: #111111;
					margin-left: 20rpx;
					padding-top: 10rpx;
				}
			}

			.delivery-item-operate {
				margin-top: 12rpx;
				.delivery-item-remark {
					font-size: 28rpx;
					color: #666666;
					margin-right: 20rpx;
					word-wrap: break-word;
					word-break: break-all;
				}

				.transferred_order {
					width: 170rpx;
					color: #666;
					background-color: #d1d1d1;
					border-radius: 30rpx;
					line-height: 56rpx;
					text-align: center;
					margin:0 30rpx;
					font-size: 26rpx;
					height: 56rpx;
				}
			}

			.delivery-item-time {
				margin-top: 20rpx;
				font-size: 28rpx;
				color: $uni-color-theme;
			}
		}
	}

	.popup-service {

		.popup-service-title {
			font-size: 36rpx;
			border-bottom: 20rpx solid #F6F6F6;
			text-align: center;
			padding: 34rpx 0;
		}

		.popup-search-title {
			padding: 34rpx 30rpx;
		}

		.popup-service-list {
			padding: 30rpx;
			height: 60vh;

			.popup-service-list-title {
				font-size: 24rpx;
				color: #111111;
				// text-align: center;
				margin-bottom: 36rpx;

			}

			.popup-service-item {
				margin-bottom: 20rpx;
				border-radius: 16rpx;
				background: #F6F6F6;
				padding: 26rpx 40rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.popup-service-image {
					width: 36rpx;
					height: 36rpx;
					margin-right: 5rpx;
				}

				.popup-service-name {
					font-size: 28rpx;
					color: #111111;

					&.flex-cc {
						display: flex;
						flex-direction: column;
					}

					.flex-cc-t {
						line-height: 62rpx;
						font-size: 32rpx;
					}

					.flex-cc-b {
						color: #666666;
					}
				}

				.popup-service-describe {
					color: #fff;
					margin-top: 10rpx;
					background-color: #BB0024;
					padding: 10rpx 30rpx;
					border-radius: 30rpx;
				}

				.popup-service-rest {
					color: #4b4b4b;
					background-color: #8f8e8e;
				}
			}
		}


	}

	.transferred_time {
		line-height: 29px;
	}

	.strategy_pop {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		background: rgba(0, 0, 0, 0.7);
		z-index: 99999;

		.pop_box {
			margin: 50rpx 50rpx 0 50rpx;
			display: flex;
			justify-content: space-between;
		}

		.button_pop {
			margin-top: 50rpx;
			line-height: 80rpx;
			text-align: center;
			width: 40%;
			color: rgb(255, 255, 255);
			overflow: visible;
			color: #666;
			background-color: #d1d1d1;
			border-radius: 100rpx;
		}

		.image {
			border-radius: 16rpx;
			padding: 100rpx 34rpx 30rpx 34rpx;

			.image-title {
				font-size: 32rpx;
				color: #111111;
				font-weight: bold;
			}

			.image-tips {
				margin-top: 16rpx;
				margin-bottom: 30rpx;
				font-size: 24rpx;
				color: #999999;
			}
		}
	}
}
</style>
